﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Threading;

using MINERP.COM;
using MINERP.DAL;
namespace MINERP.BLL.InfoConfig
{
    public delegate void DelSetPro(int pros);
    public class DataClearBLL
    {
        Thread thread = null;

        public ProgressBar ProgressBar { get; set; }
 
        public void ClearPinBanData(DateTime dt)
        {
            using (newSampleYPDBEntities entities = new newSampleYPDBEntities())
            {
                List<Board> list = entities.Board.Where(b => b.lastPrintTime <= dt && b.status ==(int)EnumBoardStatus.Printed).ToList();
                ProgressBar.Maximum = list.Count;
                ProgressBar.Value = 0;
                foreach (var item in list)
                {
                    if (File.Exists(item.picPath))
                    {
                        File.Delete(item.picPath);
                    }
                    entities.DeleteObject(item);
                    entities.SaveChanges();
                    ProgressBar.Value += 1;
                    Application.DoEvents();
                }
            }

          
 
        }

        //// <summary>
        /// 设置进度条内容
        /// </summary>
        /// <param name="pros">渐变的值</param>
        private void SetProContent(int pros)
        {
            if (pros <= 100)
            {
                ProgressBar.Value= pros;
            }
            else
            {
                thread.Abort();//终止线程
            }
        }


        ///// <summary>
        /// 阻止当前线程
        /// </summary>
        private void SleepThread()
        {
            for (int i = 0; i < 500; i++)
            {
                Thread.Sleep(100);
                //修改进度条的前进速度,可修改[/]号后面的数字,数字越小,速度越快
                SetProContent(100 * i / 30);
            }
        }
    }
}
